home *** CD-ROM | disk | FTP | other *** search
- Path: info.spt.net.cn!usenet
- From: Xu Yifeng <jafd@public.sta.net.cn>
- Newsgroups: comp.lang.c++
- Subject: Re: ostrstream: Who knows it exectly?
- Date: Wed, 31 Jan 1996 06:41:58 -0800
- Organization: Shanghai Post & Telecommunication
- Message-ID: <310F7FB6.3321@public.sta.net.cn>
- References: <4el56r$357@fsuj01.rz.uni-jena.de>
- NNTP-Posting-Host: ts1-7.sta.net.cn
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6b (Win16; I)
-
- Tilo Koerbs wrote:
- >
- > Look at this piece of code:
- >
- > ostrstream buf; // dynamic buffer.
- > // Fill buf...
- > buf << ends; // Append NULL-byte.
- > char *p = buf.str(); // Freeze buffer.
- >
- > And now the problem: The users must delete the buffer
- > by there own. But HOW???
- > This way: delete p;
- > Or this way: delete [] p;
- >
- > Different books give different answers!
- > Is it implementation dependend? (I don't think so!)
- > Or can I do both? (I don't think so too!)
-
- Hi,
-
- the following is Watcom C++ document:
- --------------------------------------------------------
- #include <strstrea.h>
- public:
- char *ostrstream::str();
-
- emantics:
- The str public member function creates a pointer to the buffer being
- used by the ostrstream object. If the ostrstream object was created
- without dynamic allocation (static mode), the pointer is the same as the
- buffer pointer passed in the constructor.
-
- For ostrstream objects using dynamic allocation, the str public member
- function makes an implicit call to the strstreambuf::freeze member
- function. If nothing has been written to the ostrstream object, the
- returned pointer will be NULL.
-
- Note that the buffer does not necessarily end with a null character. If
- the pointer returned by the str public member function is to be
- interpreted as a C string, it is the program's responsibility to ensure
- ------------------------------------------------------------
-
- The document don't say if the dynamic buffer will be automatic freed
- or not. but think of its base class, the dynamic buffer should be
- automatic freeed.
-
- Regards,
- Xu Yifeng
-